package kr.school.service;

import java.util.Comparator;
import java.util.Scanner;

import kr.school.dao.InterfaceDAO;
import kr.school.vo.Student;

public class StudentService extends ServiceItem<Student>{

	public StudentService(InterfaceDAO<Student> dao, Scanner sc) {
		super(dao, sc);
	}

	@Override
	public Student inputItemInfo(boolean gubun) {
		System.out.println("학번 이름");
		Student std = new Student(sc.nextInt(), sc.next().trim());
		if(gubun) {
			System.out.println("국어 영어 수학");
			std.setKor(sc.nextInt());
			std.setEng(sc.nextInt());
			std.setMath(sc.nextInt());
		}
		return std;
	}

	@Override
	public void prnSubMenu() {
		System.out.println("1.이름순 정렬\n2.총점순 정렬\n3.번호순 정렬");
		int res = sc.nextInt();
		switch(res) {
			case 1:
				dao.prnListItem(new Comparator<Student>() {
					@Override
					public int compare(Student o1, Student o2) {
						return o1.getStdName().hashCode() - o2.getStdName().hashCode();
					}
				});
				break;
			case 2:
				dao.prnListItem(new Comparator<Student>() {
					@Override
					public int compare(Student o1, Student o2) {
						return o1.totalScore() - o2.totalScore();
					}
				});
				break;
			default:
				dao.prnListItem(null);
		}
	}
}